﻿require([
"jquery",
"ko",
"bootstrap",
"jquery-slimscroll",
"akcy"], function ($, ko) {
    var akcy = arguments[arguments.length - 1];
    akcy.ui.init();
    var currentBranche = window.parent.currentuser().branche;
    var currentNode = window.parent.currentuser().node;
    var curDate = new Date();
    var time = new Date(curDate.getTime()).toLocaleDateString();
    var monthtime = new Date(curDate.setMonth((curDate.getMonth() - 1))).toLocaleDateString();
    
    //代收放款
    var paymentcollectiontable = akcy.table().options({
        fields: [
             { field: 'curTime', value: ko.observable(time), method: akcy.querymethod.equal }
        ],
        headers: [
        ],
        fixed: true,
        dataQueryUrl: '/ak56api/Console/GetPaymentCollectionList'
    }).optionsExtend({
        curTime: ko.observable(time),
        mulitiplyTime: function () {
            paymentcollectiontable.getInstance().curTime(new Date(new Date(paymentcollectiontable.getInstance().curTime()).getTime() - 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetPaymentCollectionMulitiplyandAddList?time=" + paymentcollectiontable.getInstance().curTime()).done(function () {
                paymentcollectiontable.load();
            });
        },
        addTime: function () {
            paymentcollectiontable.getInstance().curTime(new Date(new Date(paymentcollectiontable.getInstance().curTime()).getTime() + 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetPaymentCollectionMulitiplyandAddList?time=" + paymentcollectiontable.getInstance().curTime()).done(function () {
                paymentcollectiontable.load();
            });
        },
        currentTime: function () {
            paymentcollectiontable.getInstance().curTime(time);
            akcy.ajaxpost("/ak56api/Console/GetPaymentCollectionMulitiplyandAddList?time=" + paymentcollectiontable.getInstance().curTime()).done(function () {
                paymentcollectiontable.load();
            });
        },
        searched: function () {
            var SKToday = 0;
            var SKMonth = 0;
            var FKToday = 0;
            var FKMonth = 0;

            paymentcollectiontable.getInstance().recordSet().each(function (item) {
                SKToday += item.SKToday;
                SKMonth += item.SKMonth;
                FKToday += item.FKToday;
                FKMonth += item.FKMonth;
            });
            $(".SKToday").text(SKToday.toFixed(2));
            $(".SKMonth").text(SKMonth.toFixed(2));
            $(".FKToday").text(FKToday.toFixed(2));
            $(".FKMonth").text(FKMonth.toFixed(2));

        },
    }).bind("paymentcollectionlist").load();

    //干线发车
    var vehicletable = akcy.table().options({
        fields: [
             { field: 'curTime', value: ko.observable(time), method: akcy.querymethod.equal }
        ],
        headers: [
        ],
        fixed: true,
        dataQueryUrl: '/ak56api/Console/GetVehiclelist'
    }).optionsExtend({
        curTime: ko.observable(time),
        mulitiplyTime: function () {
            vehicletable.getInstance().curTime(new Date(new Date(vehicletable.getInstance().curTime()).getTime() - 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetVehiclelistMulitiplyandAddList?time=" + vehicletable.getInstance().curTime()).done(function () {
                vehicletable.load();
            });
        },
        addTime: function () {
            vehicletable.getInstance().curTime(new Date(new Date(vehicletable.getInstance().curTime()).getTime() + 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetVehiclelistMulitiplyandAddList?time=" + vehicletable.getInstance().curTime()).done(function () {
                vehicletable.load();
            });
        },
        currentTime: function () {
            vehicletable.getInstance().curTime(time);
            akcy.ajaxpost("/ak56api/Console/GetVehiclelistMulitiplyandAddList?time=" + vehicletable.getInstance().curTime()).done(function () {
                vehicletable.load();
            });
        },
        searched: function () {
            var DepartureCountSum = 0;
            var OrdersCountSum = 0;
            var TrancateOrderMoneySum = 0;
            var LongDistanceMoneySum = 0;
            var AccountSum = 0;

            vehicletable.getInstance().recordSet().each(function (item) {
                DepartureCountSum += item.DepartureCountSum;
                OrdersCountSum += item.OrdersCountSum;
                TrancateOrderMoneySum += item.TrancateOrderMoneySum;
                LongDistanceMoneySum += item.LongDistanceMoneySum;
                AccountSum += item.TrancateOrderMoneySum - item.LongDistanceMoneySum;
            });
            $(".DepartureCountSum").text(DepartureCountSum);
            $(".OrdersCountSum").text(OrdersCountSum);
            $(".TrancateOrderMoneySum").text(TrancateOrderMoneySum.toFixed(2));
            $(".LongDistanceMoneySum").text(LongDistanceMoneySum.toFixed(2));
            $(".AccountSum").text(AccountSum.toFixed(2));
        },
        gotopage: function () {
            akcy.openwindow("代收放款", 'dsPay', true, "/application/Finance/dsPay.html");
        }
    }).bind("vehiclelist").load();

    //收货量
    var receivingtable = akcy.table().options({
        fields: [
             { field: 'curTime', value: ko.observable(time), method: akcy.querymethod.equal }
        ],
        headers: [
        ],
        fixed: true,
        dataQueryUrl: '/ak56api/Console/GetReceivinglist'
    }).optionsExtend({
        curTime: ko.observable(time),
        mulitiplyTime: function () {
            receivingtable.getInstance().curTime(new Date(new Date(receivingtable.getInstance().curTime()).getTime() - 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetReceivingMulitiplyandAddList?time=" + receivingtable.getInstance().curTime()).done(function () {
                receivingtable.load();
            });
        },
        addTime: function () {
            receivingtable.getInstance().curTime(new Date(new Date(receivingtable.getInstance().curTime()).getTime() + 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetReceivingMulitiplyandAddList?time=" + receivingtable.getInstance().curTime()).done(function () {
                receivingtable.load();
            });
        },
        currentTime: function () {
            receivingtable.getInstance().curTime(time);
            akcy.ajaxpost("/ak56api/Console/GetReceivingMulitiplyandAddList?time=" + receivingtable.getInstance().curTime()).done(function () {
                receivingtable.load();
            });
        },
        searched: function () {
            var OrdersCountSum = 0;
            var TrancateOrderMoneySum = 0;
            var TrancateOrderMonthMoneySum = 0;
            var BudgetMonthMoneySum = 0;

            receivingtable.getInstance().recordSet().each(function (item) {
                OrdersCountSum += item.OrdersCountSum;
                TrancateOrderMoneySum += item.TrancateOrderMoneySum;
                TrancateOrderMonthMoneySum += item.TrancateOrderMonthMoneySum;
                BudgetMonthMoneySum += item.BudgetMonthMoneySum;
            });
            $(".OrdersCountSum").text(OrdersCountSum);
            $(".TrancateOrderMoneySum").text(TrancateOrderMoneySum.toFixed(2));
            $(".TrancateOrderMonthMoneySum").text(TrancateOrderMonthMoneySum.toFixed(2));
            $(".BudgetMonthMoneySum").text(BudgetMonthMoneySum.toFixed(2));
        },
        gotopage: function () {
            akcy.openwindow("托单查询", 'tdcx', true, "/application/TransportOrder/transportorderlist.html?type=S");
        }
    }).bind("receivinglist").load();

    //资金流转
    var fundsflowtable = akcy.table().options({
        fields: [
             { field: 'curTime', value: ko.observable(time), method: akcy.querymethod.equal }
        ],
        headers: [
        ],
        fixed: true,
        dataQueryUrl: '/ak56api/Console/GetFundsFlowlist'
    }).optionsExtend({
        curTime: ko.observable(time),
        mulitiplyTime: function () {
            fundsflowtable.getInstance().curTime(new Date(new Date(fundsflowtable.getInstance().curTime()).getTime() - 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetFundsFlowMulitiplyandAddList?time=" + fundsflowtable.getInstance().curTime()).done(function () {
                fundsflowtable.load();
            });
        },
        addTime: function () {
            fundsflowtable.getInstance().curTime(new Date(new Date(fundsflowtable.getInstance().curTime()).getTime() + 1 * 24 * 60 * 60 * 1000).toLocaleDateString());
            akcy.ajaxpost("/ak56api/Console/GetFundsFlowMulitiplyandAddList?time=" + fundsflowtable.getInstance().curTime()).done(function () {
                fundsflowtable.load();
            });
        },
        currentTime: function () {
            fundsflowtable.getInstance().curTime(time);
            akcy.ajaxpost("/ak56api/Console/GetFundsFlowMulitiplyandAddList?time=" + fundsflowtable.getInstance().curTime()).done(function () {
                fundsflowtable.load();
            });
        },
        searched: function () {
            var RD_Huitoday = 0;
            var RD_Huimonth = 0;
            var RD_WeiHuiLS = 0;
            var RD_WeiHui = 0;

            fundsflowtable.getInstance().recordSet().each(function (item) {
                RD_Huitoday += item.RD_Huitoday;
                RD_Huimonth += item.RD_Huimonth;
                RD_WeiHuiLS += item.RD_WeiHuiLS;
                RD_WeiHui += item.RD_WeiHui;
            });
            $(".RD_Huitoday").text(RD_Huitoday);
            $(".RD_Huimonth").text(RD_Huimonth.toFixed(2));
            $(".RD_WeiHuiLS").text(RD_WeiHuiLS.toFixed(2));
            $(".RD_WeiHui").text(RD_WeiHui.toFixed(2));
        },
        gotopage: function () {
            akcy.openwindow("代收放款", 'dsPay', true, "/application/Finance/dsPay.html");
        }
    }).bind("fundsflowlist").load();
});